package org.example.core.valid.annontation;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

import java.util.HashSet;
import java.util.Set;

/**
 * @author 小杰_cc
 * @version 1.0
 */
public class BoolValueConstrainValidator implements ConstraintValidator<BoolValue, Boolean> {
    private Set<Boolean> set =  new HashSet<>();


    @Override
    public void initialize(BoolValue constraintAnnotation) {
        boolean[] value = constraintAnnotation.value();
        for (boolean b : value) {
            set.add(b);
        }
    }

    @Override
    public boolean isValid(Boolean aBoolean, ConstraintValidatorContext constraintValidatorContext) {
        return set.contains(aBoolean);
    }
}
